import request from './request';
import type { Person, PersonDetailDTO, PersonFormData, Event, EventFormData, AddRelationRequest } from '@/types/api';

// === 成员接口 ===
export const getAllPersonsApi = (): Promise<Person[]> => request.get('/api/persons');
export const getPersonByIdApi = (id: number): Promise<Person> => request.get(`/api/persons/${id}`);
export const getPersonDetailsApi = (id: number): Promise<PersonDetailDTO> => request.get(`/api/persons/${id}/details`);
export const addPersonApi = (data: PersonFormData): Promise<Person> => request.post('/api/persons', data);
export const updatePersonApi = (id: number, data: PersonFormData): Promise<Person> => request.put(`/api/persons/${id}`, data);
export const deletePersonApi = (id: number): Promise<void> => request.delete(`/api/persons/${id}`);

// === 事件接口 ===
export const getEventsByPersonIdApi = (personId: number): Promise<Event[]> => request.get(`/api/events/person/${personId}`);
export const addEventApi = (data: EventFormData): Promise<Event> => request.post('/api/events', data);
export const updateEventApi = (id: number, data: EventFormData): Promise<Event> => request.put(`/api/events/${id}`, data); // 【新增】更新事件API
export const deleteEventApi = (id: number): Promise<void> => { // 【新增】删除事件API
    return request.delete(`/api/events/${id}`);
};

// === 关系接口 ===
export const addRelationApi = (data: AddRelationRequest): Promise<any> => request.post('/api/relations', data);

export const deleteRelationApi = (id: number): Promise<void> => {
    return request.delete(`/api/relations/${id}`);
};

